//
//  LBDownLoader.h
//  FBSnapshotTestCase
//
//  Created by liubo on 2021/12/18.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, LBDownLoadState) {
    LBDownLoadStatePause, //暂停
    LBDownLoadStateDownLoading, //正在下载
    LBDownLoadStatePauseSuccess,
    LBDownLoadStatePauseFailed
};

typedef void (^DownLoadInfoBlock)(long long totalSize);
typedef void (^StateChangeBlcok) (LBDownLoadState state);
typedef void (^ProgressBlock)(float progress);
typedef void (^SuccessBlock)(NSString *filePath);
typedef void (^FailedBlock)(void);

@interface LBDownLoader : NSObject

//保存的文件名，如果没有传，则使用下载链接的最后一段路径
@property (nonatomic, copy) NSString *fileName;

// 一个下载器,对应一个下载任务
- (void)downLoader:(NSURL*)url
      downLoadInfo:(DownLoadInfoBlock)downLoadInfo
          progress:(ProgressBlock)progressBlock
           success:(SuccessBlock)successBlock
            failed:(FailedBlock)failedBlock;

- (void)downLoader:(NSURL*)url
      downloadPath:(NSString *)downLoadPath
          tempPath:(NSString *)tempPath
      downLoadInfo:(DownLoadInfoBlock)downLoadInfo
          progress:(ProgressBlock)progressBlock
           success:(SuccessBlock)successBlock
            failed:(FailedBlock)failedBlock;

- (void)downLoader:(NSURL*)url;
/// 暂停
- (void)pauseCurrentTask;
/// 取消
- (void)cancleCurrentTask;
/// 取消和删除
- (void)cancleAndClean;
// 继续任务
- (void)resumeCurrentTask;

#pragma mark -- <数据>
@property (nonatomic,assign,readonly)LBDownLoadState state;
@property (nonatomic,copy) DownLoadInfoBlock downLoadInfo;
@property (nonatomic,copy) StateChangeBlcok stateChange;
@property (nonatomic,assign,readonly)float progress;
@property (nonatomic,copy) ProgressBlock progressChange;
@property (nonatomic,copy) SuccessBlock successBlock;
@property (nonatomic,copy) FailedBlock failedBlock;

@end

NS_ASSUME_NONNULL_END
